<!DOCTYPE html>  
<html>
    <meta charset="utf-8" />  
    <title>快速算法</title>  
<body>
    <h1>快速算法</h1>
    <h2>
        快速排序也许是最常用的排序算法了。它的复杂度为O(nlogn)，
        且它的性能通常比其他的复杂度为O(nlogn)的排序算法要好
    </h2>
</body>
<script>  
    // const arr = [1,4,5,8,9,2,1,6];
    // Array.prototype.quickSort = function(){
    //     function quick(that){
    //         var l = that.length;
    //         if(l<=1){
    //             return that;
    //         }
    //         let leftArry = [];
    //         let rightArry = [];
    //         let firstNum = that[0];
    //         for(let i=1;i<l;i++){
    //             if(that[i]>firstNum){
    //                 rightArry.push(that[i])
                    
    //             }else{
    //                 leftArry.push(that[i])
    //             }
    //         }
    //         return [].concat(quick(leftArry),[firstNum],quick(rightArry));
    //     }
    //     return quick(this)
    // }
    
    // console.log(arr.quickSort())

    const arr=[1,2,6,8,9,4,0,11];
    Array.prototype.quickSort = function(){
        function quick(that){
            var len = that.length;
            if(len<=1){
                return that;
            }
            let middleNum = that[0];
            let right = [];
            let left = [];
            for(let i=1;i<len;i++){
                if(middleNum<that[i]){
                    right.push(that[i])
                }else{
                    left.push(that[i]);
                }
            }
            return [].concat(quick(left),[middleNum],quick(right));
        }
        return quick(this);
    }

    console.log(arr.quickSort())

</script>  
</html>